package org.gp.demo.timer.servlet;

import java.util.Date;
import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.gp.demo.timer.task.DemoTask;
import org.gp.demo.timer.task.ListenerTask;
import org.gp.demo.timer.timerfactory.DemoTimer;

public class TimerLiener implements ServletContextListener {
	private Timer listenerTimer = new Timer(true);

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		int i = 0;
		ListenerTask listenerTask = new ListenerTask();
		while (i < 10) {
			DemoTimer timer = new DemoTimer();
			DemoTask demoTask = new DemoTask();
			demoTask.init(timer);
			timer.init("" + i);
			timer.startTimer(demoTask, 120000);
			listenerTask.initTask(timer, new Date());
			i++;
		}
		Timer listenerTimer = new Timer(true);
		listenerTimer.schedule(listenerTask, 0, 60000);
	}

}
